package org.freespace.service.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.freespace.service.*;
import org.freespace.utils.SpringBeanUtil;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 作业表 服务实现类
 * </p>
 *
 * @author liuqi
 * @since 2023-05-08
 */
@Slf4j
@Service("jobLogService")
public class JobLogServiceImpl implements IJobLogService {
    @Override
    public Object getJobLog(String ip, String jobId) {
        if ("dev".equalsIgnoreCase(SpringBeanUtil.getActiveProfile())) {
            return "test"+UUID.randomUUID().toString();
        }
        String url = String.format("http://%s:%s/proxy/job/getJobLog/%s", StringUtils.trim(ip), "7777", jobId);
        String body = HttpUtil.createGet(url).execute().body();
        JSONObject jsonObject = JSONUtil.parseObj(body);
        String code = jsonObject.get("code").toString();
        return jsonObject.get("data");
    }

    @Override
    public Object searchAssertJobLog(String ip, String jobId, String searchContent, String limit) {
        if ("dev".equalsIgnoreCase(SpringBeanUtil.getActiveProfile())) {
            return "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaf" +
                    "testadsfasdfasdfasdfasdfasdfaftestadsfasdfasdfasdfasdfasdfaf" +
                    ""+UUID.randomUUID().toString();
        }
        String url = String.format("http://%s:%s/proxy/job/searchAssertJobLog", StringUtils.trim(ip), "7777");
        Map<String, String> map = new HashMap<>();
        map.put("jobId", jobId);
        map.put("searchContent", searchContent);
        map.put("searchLimit", limit);
        String body = HttpUtil.createPost(url).body(JSONUtil.toJsonStr(map)).execute().body();
        JSONObject jsonObject = JSONUtil.parseObj(body);
        String code = jsonObject.get("code").toString();
        return jsonObject.get("data");
    }
}
